{include file="Public:header2"/}
<body style="min-height: 100%;background-color: #fff">

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form onsubmit="return false;">
                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">产品名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" value="{$data['title']}" lay-verify="required" placeholder="请输入产品名称" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">奖赏类型</label>
                                <div class="layui-input-inline">
                                    <select name="shang_id" lay-verify="shang_id" lay-filter="shang_id">
                                        <option  value="">--请选择--</option>
                                        {foreach name="shang" item="vo"}
                                            <option {if condition="$data['shang_id'] eq $vo['id']"} selected{/if} value="{$vo.id}">{$vo.title}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>  
                            <div class="layui-form-item" lay-filter="">
                                <label class="layui-form-label">奖品类型</label>
                                <div class="layui-input-block">
                                    {if condition="$data['num'] neq 0"}
                                    <input type="radio" name="prize_type" value="1" title="普通奖品" {if condition="$data['prize_type'] eq 1"}checked{/if}>
                                    <input type="radio" name="prize_type" value="2" title="升级奖品" {if condition="$data['prize_type'] eq 2"}checked{/if}>
                                    <input type="radio" name="prize_type" value="3" title="降级奖品" {if condition="$data['prize_type'] eq 3"}checked{/if}>
                                    <!--<input type="radio" name="prize_type" value="5" title="首通奖品" {if condition="$data['prize_type'] eq 5"}checked{/if}>-->
                                    
                                    {elseif condition="$data['num'] eq 0"}
                                    <input type="radio" name="prize_type" value="4" title="通关奖励" {if condition="$data['prize_type'] eq 4"}checked{/if}>
                                    {/if}
                                </div>
                            </div>

                            <div class="layui-form-item" style="display:none">
                                <label class="layui-form-label">中奖概率</label>
                                <div class="layui-input-inline">
                                    <input type="number" name="gailv" value="{$data['gailv']}" lay-verify="required" placeholder="请输入中奖概率" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux" >
                                    <span style="color:red;line-height:38px">与库存数量同步</span>
                                </div>
                            </div>     
                                
                            <div class="layui-form-item">
                                <label class="layui-form-label">官方售价</label>
                                <div class="layui-input-inline">
                                    <input type="number" name="price" value="{$data['price']}" min="0.01" step="0.01" lay-verify="required" placeholder="请输入官方售价" class="layui-input">
                                </div>
                                <label class="layui-form-label">回收价格</label>
                                <div class="layui-input-inline">
                                    <input type="number" name="money" value="{$data['money']}"  min="0.01" step="0.01" lay-verify="required" placeholder="请输入回收价格" class="layui-input">
                                </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">售卖类型</label>
                                <div class="layui-input-inline" style="width: 521px;">
                                    <input type="radio"  lay-filter="goods_type_"  name="goods_type" value="1" title="现货" {if $data.goods_type eq 1} checked {/if}>
                                    <input type="radio"  lay-filter="goods_type_"  name="goods_type" value="2" title="预售" {if $data.goods_type eq 2} checked {/if}>
                                </div>
                            </div>
                            <div class="layui-form-item sale_time" {if $data.goods_type eq 1} style="display: none" {/if}>
                                <label class="layui-form-label">预售时间</label>
                                <div class="layui-input-inline" style="width: 521px;">
                                    <input type="text" name="sale_time" value="{$data.sale_time}" id="sale_time" placeholder="请选择预售时间" autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">排序值</label>
                                <div class="layui-input-inline">
                                    <input type="number" name="sort" value="{$data['sort']}" lay-verify="required" placeholder="请输入排序值" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">商品图片</label>
                                <div class="layui-input-inline">
                                    <input type="hidden" name="imgurl" value="{$data['imgurl']}" lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input" >
                                    <img style="float:left;width:120px;" class="" id="imgurl" src="{PHP} echo imageUrl($data['imgurl']){/php}">
                                </div>
                                <div class="layui-form-mid layui-word-aux">提示：建议最大不超过1M，格式为：.jpg，.jpeg，.png</div>
                            </div>
                            
     
                            
                            
                            <input type="hidden" name="id" value="{$data['id']}">
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" onclick="return check()">确认保存</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
</body>
<script type="text/javascript" src="/static/admin/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="/static/admin/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="/static/admin/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
</html>
<script type="text/javascript">
    layui.use(['layer','form','upload','element','laydate'], function(){
        var $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;
        var element = layui.element;
        var laydate = layui.laydate;
        var new_data = new Date();
        new_data.setTime(new_data.getTime()+24*60*60*1000);
        var tomorrow_time = new_data.getFullYear()+"-" + (new_data.getMonth()+1) + "-" + new_data.getDate();
        laydate.render({
            elem: '#sale_time',
            min:tomorrow_time
        });
        //现货/预售切换
        form.on('radio(goods_type_)', function (data) {
            var value = data.value;   //  当前选中的value值
            if(value == 1){
                $("#sale_time").val('')
                $(".sale_time").hide()
            }else{
                $(".sale_time").show()
            }
        });
        //执行实例
        upload.render({
            accept:'imgurl'
            ,elem: '#imgurl' //绑定元素
            ,url: '/admin/picture' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.status == 1){ //成功
                    layer.msg("上传成功",{icon:1,time:1000},function(){
                        $("#imgurl").attr("src",res.data.path);  //单图
                        $("input[name=imgurl]").val(res.data.imgurl);
                    });
                }else{ //失败
                    layer.msg(res.msg,{icon:2,anim:6,time:1500});
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('服务繁忙，请稍后再试',{icon:2,anim:6,time:1500});
            }
        });

        
        
    });

   

    function check(){
        var url="{:url('/admin/climb_list_edit')}";
        var $ = layui.$;
        var load=layer.load(2);
        $.post(url,$("form").serialize(),function(data){
            if(data.status==1){
                layer.msg(data.msg,{icon:1,time:1500},function(){
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                    parent.location.reload();
                });
            }else{
                layer.msg(data.msg,{icon:2,anim:6,time:1500},function(){
                    layer.close(load);
                });
            }
        })
    }
</script>
